home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / System / BoingBag1 / Contributions / Workbench / AslSizePatch / AslSizePatch.c < prev    next >
C/C++ Source or Header  |  1999-09-15  |  4KB  |  135 lines

  1. #include <exec/types.h>
  2. #include <dos/dos.h>
  3. #include <dos/rdargs.h>
  4. #include <libraries/asl.h>
  5. #include <proto/exec.h>
  6. #include <proto/dos.h>
  7. #include <proto/intuition.h>
  8. #include <proto/utility.h>
  9. #include <string.h>
  10.  
  11. #include "mymacros.h"
  12.  
  13. static void             PatchIt( void );
  14. static BOOL SAVEDS ASM  MyAslRequest( REG( a0 ) APTR requester, REG( a1 ) struct TagItem *tags );
  15.  
  16. static TEXT             Version[] = "$VER: AslSizePatch 1.0 (15.9.99) ©Simone Tellini";
  17. static UWORD            Width = 50, Height = 90, Top, Left;
  18. static BOOL             Center;
  19. static struct Library  *AslBase;
  20. static ULONG ASM        ( *OldAslRequest )( REG( a0 ) APTR, REG( a1 ) struct TagItem *, REG( a6 ) struct Library * );
  21.  
  22. int main( int argc, char *argv[] )
  23. {
  24.     struct RDArgs  *rdargs;
  25.     struct {
  26.             ULONG  *Width;
  27.             ULONG  *Height;
  28.             ULONG   Center;
  29.     }               Args;
  30.     int             ret = 0;
  31.  
  32.     memset( &Args, 0, sizeof( Args ));
  33.  
  34.     if( rdargs = ReadArgs( "WIDTH/N,HEIGHT/N,CENTER/S", (LONG *)&Args, NULL )) {
  35.  
  36.         if( Args.Width )
  37.             Width = *Args.Width;
  38.  
  39.         if( Args.Height )
  40.             Height = *Args.Height;
  41.  
  42.         Center = Args.Center;
  43.  
  44.         PatchIt();
  45.  
  46.         FreeArgs( rdargs );
  47.  
  48.     } else {
  49.  
  50.         PrintFault( IoErr(), argv[0] );
  51.  
  52.         ret = 20;
  53.     }
  54.  
  55.     return( ret );
  56. }
  57.  
  58. static void PatchIt( void )
  59. {
  60.     struct Screen  *scr;
  61.  
  62.     if( scr = LockPubScreen( NULL )) {
  63.  
  64.         Width  = ( scr->Width  * Width  ) / 100;
  65.         Height = ( scr->Height * Height ) / 100;
  66.         Left   = ( scr->Width  - Width  ) / 2;
  67.         Top    = ( scr->Height - Height ) / 2;
  68.  
  69.         UnlockPubScreen( NULL, scr );
  70.  
  71.         if( AslBase = OpenLibrary( "asl.library", 0 )) {
  72.  
  73.             (APTR)OldAslRequest = SetFunction( AslBase, -60, (APTR) MyAslRequest );
  74.  
  75.             Wait( SIGBREAKF_CTRL_C );
  76.  
  77.             SetFunction( AslBase, -60, (APTR)OldAslRequest );
  78.  
  79.             CloseLibrary( AslBase );
  80.         }
  81.     }
  82. }
  83.  
  84. static BOOL SAVEDS ASM MyAslRequest( REG( a0 ) APTR requester, REG( a1 ) struct TagItem *tags )
  85. {
  86.     ULONG           CenterTags[] = {
  87.                                 ASLFR_InitialLeftEdge,  Left,
  88.                                 ASLFR_InitialTopEdge,   Top,
  89.                                 TAG_MORE,               (ULONG) tags
  90.                     };
  91.     ULONG           ExtraTags[] = {
  92.                                 ASLFR_InitialWidth,     Width,
  93.                                 ASLFR_InitialHeight,    Height,
  94.                                 TAG_MORE,               Center ? (ULONG)CenterTags : (ULONG)tags
  95.                     };
  96.     struct TagItem *oldleft = NULL, *oldtop = NULL, *oldwidth, *oldheight;
  97.     BOOL            ret;
  98.  
  99.     oldwidth  = FindTagItem( ASLFR_InitialWidth,  tags );
  100.     oldheight = FindTagItem( ASLFR_InitialHeight, tags );
  101.  
  102.     if( Center ) {
  103.         oldleft = FindTagItem( ASLFR_InitialLeftEdge, tags );
  104.         oldtop  = FindTagItem( ASLFR_InitialTopEdge,  tags );
  105.     }
  106.  
  107.     if( oldleft )
  108.         oldleft->ti_Tag = TAG_IGNORE;
  109.  
  110.     if( oldtop )
  111.         oldtop->ti_Tag = TAG_IGNORE;
  112.  
  113.     if( oldwidth )
  114.         oldwidth->ti_Tag = TAG_IGNORE;
  115.  
  116.     if( oldheight )
  117.         oldheight->ti_Tag = TAG_IGNORE;
  118.  
  119.     ret = ( *OldAslRequest )( requester, (struct TagItem *) &ExtraTags, AslBase );
  120.  
  121.     if( oldleft )
  122.         oldleft->ti_Tag = ASLFR_InitialLeftEdge;
  123.  
  124.     if( oldtop )
  125.         oldtop->ti_Tag = ASLFR_InitialTopEdge;
  126.  
  127.     if( oldwidth )
  128.         oldwidth->ti_Tag = ASLFR_InitialWidth;
  129.  
  130.     if( oldheight )
  131.         oldheight->ti_Tag = ASLFR_InitialHeight;
  132.  
  133.     return( ret );
  134. }
  135.